
import java.util.Arrays;

public class LC5854Week {
    public int minimumDifference(int[] nums, int k) {
        if (nums.length==0)
            return 0;
        Arrays.sort(nums);
        int min=nums[k-1]-nums[0];
        int index=k;
        int n=nums.length;
        while (index<n){
            if (min>nums[index]-nums[index-k+1]){
                min=nums[index]-nums[index-k+1];
            }
            index++;
        }
        return min;
    }
}
